From Origin-Destination Data to Bike Bus Routes
Juan Pablo Fonseca Zamora, Joey Talbot and Robin Lovelace
fromOD2bikebus.RmdThis vignette demonstrates the complete workflow for generating bike bus routes from origin-destination data using the bicischools package. We’ll walk through the process using data from Almada, Portugal, showing how to go from raw geographic data to optimised bike bus routes.
Overview
The workflow consists of several key steps:
- Data Preparation: Load and process geographic zones and school locations
- Origin-Destination Simulation: Use gravity models to estimate student trips
-
Route Generation: Create cycling routes between
origins and destinations
- Network Analysis: Build route networks and calculate cycling uptake
- Route Optimisation: Identify and optimise bike bus routes
- Visualisation: Map results for analysis
1. Data Preparation
We’ll use census zones (BGRI) as origins and schools as destinations. First, let’s load the included sample data:
# Load sample data included with the package
data("origins_almada")
data("schools_lisbon")
data("od_data_almada")
data("routes_almada")
# Display basic information
cat("Number of origin zones:", nrow(origins_almada), "\n")
#> Number of origin zones: 181
cat("Number of schools:", nrow(schools_lisbon), "\n")
#> Number of schools: 52
cat("Number of OD pairs:", nrow(od_data_almada), "\n")
#> Number of OD pairs: 300Let’s visualise the basic geography:
tm_shape(origins_almada) +
tm_borders() +
tm_shape(schools_lisbon) +
tm_dots("red", size = 0.5) +
tm_title("Origins and Schools in Almada")2. Origin-Destination Flow Simulation
For this example, we’ll use pre-calculated OD data, but here’s how you would generate it using a gravity model:
# Example gravity model simulation (not run with sample data)
results <- sim_schools(
origins = origins_almada,
destinations = schools_lisbon,
model = "gravity",
max_dist = 3000,
balancing = "destinations",
d = distance_euclidean,
m = origin_pupils,
n = destination_n_pupils,
constraint_production = origin_pupils,
beta = 0.99944,
keep_cols = TRUE
)3. Route Generation
Generate cycling routes between origins and the selected school:
# The routes are already generated in our sample data
# Here's how you would generate them:
# routes_almada <- bici_routes(od_data_almada, distance.threshold = 5e3)
# Visualise the routes
tm_shape(origins_almada) +
tm_borders() +
tm_shape(od_data_almada) +
tm_lines(col = "grey", col_alpha = 0.3) +
tm_shape(routes_almada) +
tm_lines(col = "dodgerblue", col_alpha = 0.6, lwd = 2) +
tm_shape(schools_lisbon) +
tm_dots("red", size = 0.5) +
tm_title("Cycling Routes to School")
#> Registered S3 method overwritten by 'jsonify':
#> method from
#> print.json jsonlite